<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册账号</title>
    <style>
        body {
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f5f5f5;
        }
        .register-box {
            background-color: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            width: 300px;
            text-align: center;
        }
        h2 {
            color: #ff6b81;
            margin-top: 0;
        }
        .form-group {
            margin-bottom: 20px;
            text-align: left;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background-color: #ff6b81;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            font-size: 16px;
        }
        button:hover {
            background-color: #ff5777;
        }
        .error-message {
            color: #ff6b81;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }
        .login-link {
            margin-top: 15px;
            display: block;
            text-align: center;
        }
        .login-link a {
            color: #666;
            text-decoration: none;
        }
        .login-link a:hover {
            color: #ff6b81;
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="register-box">
        <h2>注册账号</h2>
        <div class="form-group">
            <label for="username">新账号</label>
            <input type="text" id="username" placeholder="请输入账号">
            <div class="error-message" id="username-error">账号只能由数字构成</div>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" placeholder="请输入密码">
        </div>
        <div class="form-group">
            <label for="confirm-password">确认密码</label>
            <input type="password" id="confirm-password" placeholder="请再次输入密码">
            <div class="error-message" id="password-error">两次输入的密码不一致</div>
        </div>
        <button id="register-btn">完成注册</button>
        
        <div class="login-link">
            <a href="登录.html">已有账号？立即登录</a>
        </div>
    </div>

    <script>
        // 获取DOM元素
        const usernameInput = document.getElementById('username');
        const passwordInput = document.getElementById('password');
        const confirmPasswordInput = document.getElementById('confirm-password');
        const usernameError = document.getElementById('username-error');
        const passwordError = document.getElementById('password-error');
        const registerBtn = document.getElementById('register-btn');

        // 实时检查账号格式
        usernameInput.addEventListener('input', function() {
            const username = this.value;
            // 使用正则表达式检查是否包含英文字母
            if (/[a-zA-Z]/.test(username)) {
                usernameError.style.display = 'block';
            } else {
                usernameError.style.display = 'none';
            }
        });

        // 实时检查密码一致性
        confirmPasswordInput.addEventListener('input', function() {
            const password = passwordInput.value;
            const confirmPassword = this.value;
            
            if (password !== confirmPassword && confirmPassword.length > 0) {
                passwordError.style.display = 'block';
            } else {
                passwordError.style.display = 'none';
            }
        });

        // 注册按钮点击事件
        registerBtn.addEventListener('click', function() {
            const username = usernameInput.value;
            const password = passwordInput.value;
            const confirmPassword = confirmPasswordInput.value;
            
            // 验证账号格式
            if (/[a-zA-Z]/.test(username)) {
                usernameError.style.display = 'block';
                return; // 阻止注册
            } else {
                usernameError.style.display = 'none';
            }
            
            // 验证密码是否一致
            if (password !== confirmPassword) {
                passwordError.style.display = 'block';
                return; // 阻止注册
            } else {
                passwordError.style.display = 'none';
            }
            
            // 这里可以添加实际的注册逻辑
            // 例如发送数据到服务器等
            
            // 注册成功后跳转到登录页面
            window.location.href = "登录.html";
        });
    </script>
</body>
</html>
    